# @Time : 2020/7/28 11:57
# @Author : Fioman 
# @Phone : 13149920693
import cv2 as cv
import numpy as np

"""
Scharr 比 Sobel 算子具有更高的精度.
"""
img = cv.imread("test.bmp",cv.IMREAD_GRAYSCALE)
sobelX = cv.Sobel(img,cv.CV_64F,1,0,ksize=3)
sobelY = cv.Sobel(img,cv.CV_64F,0,1,ksize=3)
sobelX = cv.convertScaleAbs(sobelX)
sobelY = cv.convertScaleAbs(sobelY)
sobelXY =cv.addWeighted(sobelX,1,sobelY,1,0)

scharrX = cv.Scharr(img,cv.CV_64F,1,0)
scharrY = cv.Scharr(img,cv.CV_64F,0,1)
scharrX = cv.convertScaleAbs(scharrX)
scharrY = cv.convertScaleAbs(scharrY)
scharrXY = cv.addWeighted(scharrX,1,scharrY,1,0)

cv.imshow("SobelX",sobelX)
cv.imshow("SobelY",sobelY)
cv.imshow("SobelXY",sobelXY)

cv.imshow("ScharrX",scharrX)
cv.imshow("ScharrY",scharrY)
cv.imshow("ScharrXY",scharrXY)

cv.waitKey(0)
cv.destroyAllWindows()
